﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using ECI.Entities;
using ECI.CommonLibrary;
using ECI.CoreLibrary;

namespace ECI.DynamicData.DataCache
{
    public class DataCache
    {
        private static Hashtable HTCache = new Hashtable();

        public static void Clear()
        {
            HTCache = new Hashtable();
        }

        public static void Add(EciTable eciTable)
        {
            if (HTCache.ContainsKey(eciTable.Code + "_" + UserInfo.Language))
            {
                HTCache.Remove(eciTable.Code + "_" + UserInfo.Language);
            }
            HTCache.Add(eciTable.Code + "_" + UserInfo.Language, eciTable);
        }

        public static EciTable Get(string code)
        {
            if (HTCache.ContainsKey(code+"_"+ UserInfo.Language))
            {
                return (EciTable)HTCache[code + "_" + UserInfo.Language];
            }
            else
            {
                EciTable myTable = null;
                if (ECI.CoreLibrary.PlatformInfo.DevFactoryFromXML)
                {
                    myTable = ECI.DynamicData.Data.DataModelFromXML.GetDataModel(code);
                }
                else
                {
                    myTable = ECI.DynamicData.Data.DataModel.GetDataModel(code);
                }
                HTCache.Add(code + "_" + UserInfo.Language, myTable);
                return myTable;
            }
        }
    }
}
